"use strict"

/**
 * leet-code(20) 有效的括号
 */
function isValid(s) {
    if (!s || s.length < 2)
        return false
    const stack = []
    // for...in... 会拿到下标
    for (let cur of s) {
        if (cur === '(')
            stack.push(')')
        else if (cur === '[')
            stack.push(']')
        else if (cur === '{')
            stack.push('}')
        else {
            if (stack.length === 0)
                return false
            if (stack.pop() !== cur)
                return false
        }
    }
    return stack.length === 0
}

console.log(isValid('()'))
console.log(isValid('()[]{}'))
console.log(isValid('(]'))